<template>
  <div class="message-detail-container">
    <!-- 顶部标题栏 -->
    <div class="header">
      <h1>贵阳（贵安）退役军人就业服务平台</h1>
    </div>

    <!-- 消息详情内容 -->
    <div class="message-content">
      <el-card class="message-card">
        <!-- 消息标题 -->
        <div class="message-title">
          <h2>{{ message.title }}</h2>
          <div class="message-meta">
            <span class="time">{{ message.dateandtime }}</span>
            <el-tag v-if="message.is_read" type="success" size="small"
              >已读</el-tag
            >
            <el-tag v-else type="danger" size="small">未读</el-tag>
          </div>
        </div>
        <!-- 消息内容 -->
        <div class="message-body">
          <div v-html="message.content"></div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { markRead } from "@/api/index";
import { useRoute } from "vue-router";
const route = useRoute();
const detailArray = ref({});
onMounted(() => {
  const encodedParam = route.query.item; // 从URL获取编码参数
  const decoded = decodeURIComponent(encodedParam);
  const data = JSON.parse(decoded);
  message.value = data;
  message.value.content = showHtml(message.value.content);
  getRead();
});
const showHtml = (str) => {
  return (
    str
      // .replace(str ? /&(?!#?\w+;)/g : /&/g, "&amp;")
      .replace(/&amp;/g, "&")
      .replace(/&lt;/g, "<")
      .replace(/&gt;/g, ">")
      .replace(/&quot;/g, '"')
      .replace(/&#39;/g, "'")
      .replace(/&ldquo;/g, "“")
      .replace(/&rdquo;/g, "”")
  );
};
//消息标记已读
const getRead = (data) => {
  let params = {
    fid: message.value.Fid,
  };
  markRead(params)
    .then((res) => {
      if (res.code == 200) {
        list.value.push(...res.data);
      } else {
      }
    })
    .catch((err) => {});
};

// 消息数据
const message = ref({});
</script>

<style scoped>
.message-detail-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f5f5;
}

.header {
  background-color: #1e88e5;
  color: white;
  padding: 15px 20px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header h1 {
  margin: 0;
  font-size: 18px;
}

.message-content {
  flex: 1;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  width: 96%;
  margin-left: 2%;
  margin-top: 20px;
}

.message-card {
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.message-title {
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
  margin-bottom: 20px;
}

.message-title h2 {
  margin: 0 0 10px 0;
  font-size: 20px;
  color: #333;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.time {
  color: #999;
  font-size: 14px;
}

.message-body {
  line-height: 1.6;
  color: #333;
  white-space: pre-line;
}

.message-attachments {
  margin-top: 30px;
  padding-top: 15px;
  border-top: 1px dashed #eee;
}

.message-attachments h3 {
  margin: 0 0 15px 0;
  font-size: 16px;
  color: #666;
}

.message-attachments ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.message-attachments li {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}

.file-size {
  margin-left: 10px;
  color: #999;
  font-size: 12px;
}
</style>